<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>我的移动端滑屏</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        /* 还是得加一个wrap，不然会与body整包了，不利于别的元素布局 */
        #wrap {
            width: 100vw;
            height: 60vw;
            /* overflow:auto; */
            overflow: hidden;
            position: relative;
        }

        #list {
            list-style: none;
            padding: 0;
            margin: 0;
            width: 500vw;
            height: 60vw;
            position: absolute;
            left: 0;
            top: 0;
        }

        #list li {
            width: 100vw;
            float: left;

        }

        #list img {
            width: 100vw;
            height: 60vw;
        }
    </style>
</head>

<body>
    <article id="wrap">
        <ul id="list">
            <li>
                <img src="img/A0.jpg" alt="">
            </li>
            <li>
                <img src="img/A1.jpg" alt="">
            </li>
            <li>
                <img src="img/A2.jpg" alt="">
            </li>
            <li>
                <img src="img/A3.jpg" alt="">
            </li>
            <li>
                <img src="img/A4.jpg" alt="">
            </li>
        </ul>
    </article>

    我真的还想再活五百年
    <script>
        var wrap = document.getElementById("wrap");
        var list = document.getElementById("list");
        var w = window.innerWidth;
        wrap.addEventListener("touchstart", () => {
            event.preventDefault(); //清除默认事件（右滑页面返回）、穿透
        })

        var oriX, nowLeft = 0,
            target;
        wrap.addEventListener("touchstart", () => {
            //记录手指初始位置
            list.style.transition = 'none';
            oriX = event.targetTouches[0].pageX;
            //如果碰到没有move情况，那么target就要设置初始值
            target = nowLeft;
        })
        wrap.addEventListener("touchmove", () => {
            //记录手指移动位置，得到位移，后将图片移动
            var nowX = event.changedTouches[0].pageX;
            target = (nowX - oriX) + nowLeft;
            list.style.left = target + "px";
        })
        wrap.addEventListener("touchend", () => {
            // 做一个图片位置吸附
            nowLeft = Math.round(target / w) * w;
            // 边缘处理
            if (nowLeft > 0) {
                nowLeft = 0;
            }

            if (nowLeft <= (-list.offsetWidth)) {
                nowLeft = list.children[0].offsetWidth - list.offsetWidth;
            }

            list.style.transition = 'left 0.5s';
            list.style.left = nowLeft + "px";

        })
    </script>
</body>

</html>